from flask import Flask, render_template
from flask_migrate import Migrate
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy

from conf.configuration import BaseConf


class Application(Flask):

    def __init__(self, import_name):
        super(Application, self).__init__(import_name)
        self.config.from_object(BaseConf)
        db.init_app(self)


db = SQLAlchemy()
app = Application(__name__)


# 404处理
@app.errorhandler(404)
def page_not_found(error):
    return render_template('404.html'), 404


# 包装/扩展app对象
manage = Manager(app)
# 1.要使用flask_migrate,必须绑定app和DB
migrate = Migrate(app, db)
